﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech;

namespace WindowsFormsApplicationRocket1
{
    public partial class Form1 : Form
    {
        MissileLauncher ml;
        System.Speech.Recognition.SpeechRecognitionEngine sre;
        public Form1()
        {
            InitializeComponent();
            
            sre = new System.Speech.Recognition.SpeechRecognitionEngine();
            sre.LoadGrammar(new System.Speech.Recognition.DictationGrammar());
            sre.SpeechRecognized += rec_SpeechRecognized;
            sre.SetInputToDefaultAudioDevice();
            ml = new MissileLauncher();
        }


        void rec_SpeechRecognized(object sender, System.Speech.Recognition.SpeechRecognizedEventArgs e)
        {
            foreach (System.Speech.Recognition.RecognizedWordUnit rwu in e.Result.Words)
            {
                if (rwu.Confidence > .8)
                { textBox2.Text += rwu.Text + " "; }
            }
            textBox2.Text += "\n";
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ml.command_reset();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ml.command_Up(convertToTime(Double.Parse(textBox1.Text)));
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ml.command_Down(convertToTime(Double.Parse(textBox1.Text)));
        }

        private void button4_Click(object sender, EventArgs e)
        {
            ml.command_Left(convertToTime(Double.Parse(textBox1.Text)));
        }

        private void button5_Click(object sender, EventArgs e)
        {
            ml.command_Right(convertToTime(Double.Parse(textBox1.Text)));
        }

        private void button6_Click(object sender, EventArgs e)
        {
            ml.command_Fire();
        }
        private int convertToTime(double degrees)
        {
            return Convert.ToInt32(Math.Floor(degrees * 190 / 9));
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            sre.RecognizeAsyncStop();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            sre.RecognizeAsync(System.Speech.Recognition.RecognizeMode.Multiple);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            sre.RecognizeAsyncStop();
        }
    }
}
